package com.heima.user.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.LoginDto;
import com.heima.model.user.dtos.LoginFormDTO;
import com.heima.user.service.ApUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;


@RestController
@RequestMapping("/api/v1/login")
@Api(value = "app端用户登录",tags = "app端用户登录")
public class ApUserLoginController {

    @Autowired
    private ApUserService apUserService;
    /**
     * 用户登录
     * @param dto
     * @return
     */
    @PostMapping("/login_auth")
    @ApiOperation("用户登录")
    public ResponseResult login(@RequestBody LoginDto dto){
        return apUserService.login(dto);
    }
    /**
     * 验证码登录
     * @param loginForm
     * @param session
     * @return
     */
    @PostMapping("/code_login")
    @ApiOperation("验证码登录")
    public ResponseResult codeLogin(@RequestBody LoginFormDTO loginForm, HttpSession session) {
        return apUserService.codeLogin(loginForm, session);
    }

    /**
     * 发送验证码
     * @param phone
     * @param session
     * @return
     */
    @GetMapping("/send_code")
    @ApiOperation("发送验证码")
    public ResponseResult sendCode(@RequestParam String phone, HttpSession session) {
        return apUserService.sendCode(phone, session);
    }

}
